import React, { Component } from "react";
import Taro from '@tarojs/taro';
import { Provider } from "react-redux";
import dva from "./utils/dva"
import models from './models';
import "./app.scss";
import {  getAllDictionaries, saveGlobalDict } from "./services/api/common";

const dvaApp = dva.createApp({
  initialState: {},
  models,
});
const store = dvaApp.getStore();
class App extends Component {
  componentWillMount() {

  }
  componentDidMount() { 
     this.requestAllDictionaries();
  }

  async onLaunch() {
    // 储存胶囊的位置信息
    const navPosition = Taro.getMenuButtonBoundingClientRect()
    Taro.setStorageSync('nav-position', JSON.stringify(navPosition))
    // 获取并储存设备数据
    const systemInfo = await Taro.getSystemInfo()
    Taro.setStorageSync('system-info', JSON.stringify(systemInfo))

  }
  componentDidShow() { }

  componentDidHide() { }

  componentDidCatchError() { 

  }
  

  /// 请求全局字典
  requestAllDictionaries(){
    getAllDictionaries().then(resp => {
      const data = resp.data
      if (resp.code === 200) {
        saveGlobalDict(data);
      }
    })
  }



  // this.props.children 是将要会渲染的页面
  render() {
    return (
      <Provider store={store}>
        {this.props.children}
      </Provider>
    )
  }
}

export default App;
